package com.itheima.mq;

import com.itheima.cst.SysConst;
import com.itheima.utils.SMSUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class SMSValifyCodeConsumer {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @RabbitListener(queues = "sms_queue")
    public void reciver(String telphone){
        String code = SMSUtil.sendSmsCode(telphone);
        if(code != null){
            redisTemplate.opsForValue().set(SysConst.SMS_VALIFYCODE + telphone,code,5, TimeUnit.MINUTES);
        }
    }

}
